<?php

namespace App\Http\Controllers\home;

use Illuminate\Http\Request;

use App\Http\Requests;

use App\Http\Controllers\Controller;

use DB;
class ListController extends Controller
{
    //列表页面
    public function index($id)
    {
        //商品遍历
        $goods = DB::table('goods')
            ->join('goodscate', 'goodscate.id', '=', 'goods.cid')
            ->join('goodsmain', 'goodsmain.gid', '=', 'goods.id')
            ->select('goods.id','goods.status','goods.biaoqian','goods.cid','goodscate.name','goodscate.status','goodsmain.gid','goodsmain.title','goodsmain.colour','goodsmain.hwprice','goodsmain.price','goodsmain.status','goodsmain.ftitle','goodsmain.pic0','goodsmain.buy')
            ->where([
                ['goods.status', '=', '1'],
                ['goodscate.status', '=', '1'],
                ['goodsmain.status', '=', '1'],
            ])->get();

        // 查分类表中状态为1且cid为当前遍历出来的id号
        $goodscate = DB::table('goodscate')
            ->where([
                ['goodscate.status', '1'],
                ['goodscate.cid', $id],
            ])->get();

        // 商品表
        $goodscId = DB::table('goods')->where('status', '1')->get();

        // 商品评价
        $storecomment = DB::table('storecomment')->get();

        // 解析模板
        return view('home.list',['goods' => $goods,'goodscId' => $goodscId,'id' => $id,'goodscate' => $goodscate,'storecomment' => $storecomment]);
    }
    public function priceA($id)
    {
        //商品遍历
        $goods = DB::table('goods')
            ->join('goodscate', 'goodscate.id', '=', 'goods.cid')
            ->join('goodsmain', 'goodsmain.gid', '=', 'goods.id')
            ->select('goods.id','goods.status','goods.biaoqian','goods.cid','goodscate.name','goodscate.status','goodsmain.gid','goodsmain.title','goodsmain.colour','goodsmain.hwprice','goodsmain.price','goodsmain.status','goodsmain.ftitle','goodsmain.pic0','goodsmain.buy')
            ->where([
                ['goods.status', '=', '1'],
                ['goodscate.status', '=', '1'],
                ['goodsmain.status', '=', '1'],
            ])->orderBy('goodsmain.price')->get();

        $goodscate = DB::table('goodscate')
            ->where([
                ['goodscate.status', '1'],
                ['goodscate.cid', $id],
            ])->get();

        $goodscId = DB::table('goods')->where('status', '1')->get();
        $storecomment = DB::table('storecomment')->get();
        
        
        return view('home.list',['goods' => $goods,'goodscId' => $goodscId,'id' => $id,'goodscate' => $goodscate,'storecomment' => $storecomment]);

    }

    public function priceD($id)
    {
        //商品遍历
        $goods = DB::table('goods')
            ->join('goodscate', 'goodscate.id', '=', 'goods.cid')
            ->join('goodsmain', 'goodsmain.gid', '=', 'goods.id')
            ->select('goods.id','goods.status','goods.biaoqian','goods.cid','goodscate.name','goodscate.status','goodsmain.gid','goodsmain.title','goodsmain.colour','goodsmain.hwprice','goodsmain.price','goodsmain.status','goodsmain.ftitle','goodsmain.pic0','goodsmain.buy')
            ->where([
                ['goods.status', '=', '1'],
                ['goodscate.status', '=', '1'],
                ['goodsmain.status', '=', '1'],
            ])->orderBy('goodsmain.price','desc')->get();

        $goodscate = DB::table('goodscate')
            ->where([
                ['goodscate.status', '1'],
                ['goodscate.cid', $id],
            ])->get();

        $goodscId = DB::table('goods')->where('status', '1')->get();
        $storecomment = DB::table('storecomment')->get();
        
        
        return view('home.list',['goods' => $goods,'goodscId' => $goodscId,'id' => $id,'goodscate' => $goodscate,'storecomment' => $storecomment]);

    }

}
